package com.gjh.xiaokabang2code.common;

public class HideCharactersUtil {
    public static String reservedFirstWord(String inputString) {
        if (inputString == null || inputString.isEmpty()) {
            return null;
        }
        if (inputString.length() == 1) {
            return inputString;
        } else {
            char firstChar = inputString.charAt(0);
            StringBuilder hiddenString = new StringBuilder();
            hiddenString.append(firstChar);
            for (int i = 1; i < inputString.length(); i++) {
                hiddenString.append('*');
            }
            return hiddenString.toString();
        }
    }
    public static String convertToFourDigits(String input) {
        if (input == null || input.isEmpty()) {
            return null;
        }
        if (input.length() == 19 && input.matches("\\d+")) {
            return input.substring(15); // 从第2位开始截取
        } else {
            return null; // 输入无效
        }
    }


    public static String phoneHideDigits(String input, int start, int end) {
        if (input == null || input.isEmpty()) {
            return null;
        }
        if (input.length() != 11) {
            return input; // 输入无效，返回原始手机号
        }

        StringBuilder hiddenNumber = new StringBuilder();
        hiddenNumber.append(input, 0, start);
        hiddenNumber.append("****");
        hiddenNumber.append(input.substring(end));

        return hiddenNumber.toString();
    }

    public static String stuNumberHideDigits(String input, int start, int end) {
        if (input == null || input.isEmpty()) {
            return null;
        }
        StringBuilder hiddenNumber = new StringBuilder();
        hiddenNumber.append(input, 0, start);
        hiddenNumber.append("***");
        hiddenNumber.append(input.substring(end));

        return hiddenNumber.toString();
    }
}
